<template>
  <div>
    <h2>测试web组件语言包电话试试</h2>
  </div>
</template>
<script lang='ts'>
import { Component, Vue } from "vue-property-decorator";
/** 获取cookie */
function getCookie(name: string) {
  if (document.cookie.length > 0) {
    let start = document.cookie.indexOf(name + "=");
    if (start != -1) {
      start = start + name.length + 1;
      let end = document.cookie.indexOf(";", start);
      if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(start, end));
    }
  }
  return "";
}
/** 语言 */
const languages = getCookie("languages") || "zh-Hans";
import en from "../../node_modules/element-ui/lib/locale/lang/en.js";
import zhCN from "../../node_modules/element-ui/lib/locale/lang/zh-CN.js";
// web components组件必须引入并实例，不然标签无法编译
import ElementUI from "element-ui";
Vue.use(ElementUI, { zIndex: 3000, locale: languages == "en" ? en : zhCN });
interface State {
  /** 数据状态 */
  loading: boolean;
}
@Component
export default class Index extends Vue {
  /** 数据 */
  state: State = {
    loading: false,
  };
  /** 生命周期 */
  created() {
    const lang = fetch(
      `${process.env.BASE_URL.replace(/\/$/, "")}/locale/${languages}.json`
    )
      .then((res) => res.json())
      .catch(() => ({}));

    (window as any)["i18n"] = Object.assign({}, (window as any).i18n, lang);
  }
  /** 方法 */
  /** 监听 */
  /** 计算属性 */
}
</script>
<style lang='scss' scoped></style>
<style>
/* 需要引入相关的图标，样式文件等 */
@import url("/publicData/styles/theme/fonts/element-icons.woff");
@import url("/publicData/styles/theme/index.css");
</style>